function ReemplazarComa(pevent, ctrl)
{
    var levent = window.event ? window.event : pevent;
    var tecla = levent.keyCode;

    switch(tecla){
        case 188:
            if(ctrl.value.indexOf(".") == -1){
                ctrl.value = ctrl.value.replace(/,/,".");
            }
            else{
                 ctrl.value = ctrl.value.replace(/,/,"");
            }
        break;

        case 110:
        case 190:
            if(ctrl.value.match(/\./g).length > 1){
                alert("- El número ingresado es inválido, contiene más de un separador decimal");
                ctrl.select();
                ctrl.focus();
            }
        break;
    }

    return true;
}

function MascaraMoney(obj,caracter){
	patron = /[\*,\+,\(,\),\?,\,$,\[,\],\^]/;
	valor = obj.value;
	largo = valor.length;
	crtr = true;
	if(isNaN(caracter) || patron.test(caracter) == true){
		if (patron.test(caracter)==true){
			caracter = "\\," + caracter;
		}
		//***que no sea coma, si es coma, dejo sólo una
		if (caracter != '\\,') {
			carcter = new RegExp(caracter,"g");
			valor = valor.replace(carcter,"");
			obj.value = valor;
			crtr = false;
		}//***
	}
	else{

		var nums = new Array();
		cont = 0;
		for(m=0;m<largo;m++){
			if(valor.charAt(m) == "." || valor.charAt(m) == " ")
				{continue;}
			else{
				nums[cont] = valor.charAt(m);
				cont++;
			}
		}
	}

	var posicion = obj.value.indexOf(",");
	if (posicion == -1) {//***si no hay coma

		var cad1="",cad2="",tres=0;
		if(largo > 3 && crtr == true){
			for (k=nums.length-1;k>=0;k--){
				cad1 = nums[k];
				cad2 = cad1 + cad2;
				tres++;
				if((tres%3) == 0){
					if(k!=0){
						cad2 = "." + cad2;
					}
				}
			}
			obj.value = cad2;
		}

	}//***si ya hay una coma
	else{
	      //Si agregan más de una coma o más de 2 decimales, se eliminan
	      posdecimal = obj.value.substring(posicion, obj.value.length-1).length;
	      if ((posicion != obj.value.lastIndexOf(",")) || (posdecimal>2)) {
				obj.value = obj.value.substring(0,obj.value.length-1);
	      }
	}
}

function ShowImpresionTramite(idTramite){
    var page = "index.php?page=RegularizacionHabitacional.ImpresoTramite&IdTramite=" + idTramite;
    var wnd =  window.open(page + "&dialog=true", "Tramite", "scrollbars=1,top=0,left=0,width=800,height=500,resizable=1,status=no,toolbar=no,menubar=no,location=no");
    wnd.focus();

}

function ShowComprobanteCuota(){
    var page = "index.php?page=RecuperoFinanciero.UpdateCuota";
    var wnd =  window.open(page + "&dialog=true", "Comprobante", "scrollbars=1,top=0,left=0,width=400,height=300,resizable=1,status=no,toolbar=no,menubar=no,location=no");
    wnd.focus();

}

function ShowDocumentoVinculante(id){

    var page = "index.php?page=Compras.DocumentoVinculanteDetalle&id=" + id;

/*     window.open(page, null, "height=600,width=600,status=no,toolbar=yes,menubar=yes,location=no");*/
    var wnd =  window.open(page + "&dialog=true", "Reportes", "scrollbars=1,top=0,left=0,width=800,height=600,resizable=1,status=no,toolbar=no,menubar=no,location=no");
    wnd.focus();


}
function ShowDocVinculantesCertObra(id, idCertificado){
    var page = "index.php?page=Obras.DocumentoVinculanteDetalle&id=" + id + "&idCertificado=" + idCertificado;

/*     window.open(page, null, "height=600,width=600,status=no,toolbar=yes,menubar=yes,location=no");*/
    var wnd =  window.open(page + "&dialog=true", "Reportes", "scrollbars=1,top=0,left=0,width=800,height=600,resizable=1,status=no,toolbar=no,menubar=no,location=no");
    wnd.focus();

}

function ShowContrato(id){
    var page = "index.php?page=Compras.ContratoDetalle&id=" + id;

    /*window.open(page, null, "height=600,width=600,status=no,toolbar=yes,menubar=yes,location=no");*/
    var wnd =  window.open(page + "&dialog=true", "Reportes", "scrollbars=1,top=0,left=0,width=800,height=600,resizable=1,status=no,toolbar=no,menubar=no,location=no");
    wnd.focus();

}

function ShowFactura(id){
    var page = "index.php?page=Compras.FacturaDetalle&id=" + id;

    /*window.open(page, null, "height=600,width=600,status=no,toolbar=yes,menubar=yes,location=no");*/
    var wnd =  window.open(page + "&dialog=true", "Reportes", "scrollbars=1,top=0,left=0,width=800,height=600,resizable=1,status=no,toolbar=no,menubar=no,location=no");
    wnd.focus();

}

function ShowOrdenCompra(id){
    var page = "index.php?page=Compras.OrdenCompraDetalle&id=" + id;

    /*window.open(page, null, "height=600,width=600,status=no,toolbar=yes,scrollbars=yes,menubar=yes,location=no");*/
    var wnd =  window.open(page + "&dialog=true", "Reportes", "scrollbars=1,top=0,left=0,width=800,height=600,resizable=1,status=no,toolbar=no,menubar=no,location=no");
    wnd.focus();

}

function ShowRemito(id){
    var page = "index.php?page=Compras.RemitoDetalle&id=" + id;

    /*window.open(page, null, "height=600,width=600,status=no,toolbar=yes,menubar=yes,location=no");*/
    var wnd =  window.open(page + "&dialog=true", "Reportes", "scrollbars=1,top=0,left=0,width=800,height=600,resizable=1,status=no,toolbar=no,menubar=no,location=no");
    wnd.focus();

}

function ShowOrdenPago(id){
    var page = "index.php?page=Liquidaciones.OrdenPagoDetalle&id=" + id;

    /*window.open(page, null, "height=600,width=600,status=no,toolbar=yes,menubar=yes,location=no");*/
    var wnd =  window.open(page + "&dialog=true", "Reportes", "scrollbars=1,top=0,left=0,width=800,height=600,resizable=1,status=no,toolbar=no,menubar=no,location=no");
    wnd.focus();

}

function ShowRendicionViatico(idAgente, idExpediente){
    var page = "index.php?page=Viaticos.RendicionDetalle&idAgente=" + idAgente + "&idExpediente=" + idExpediente;

    /*window.open(page, null, "height=600,width=600,status=no,toolbar=yes,scrollbars=yes,menubar=yes,location=no");*/
    var wnd =  window.open(page + "&dialog=true", "Reportes", "scrollbars=1,top=0,left=0,width=800,height=600,resizable=1,status=no,toolbar=no,menubar=no,location=no");
    wnd.focus();

}

function FormatoCuit(event, ctrl)
{
/*
*key
*[48-57] = [0-9]
*8 = backspace
*46 = delete
*37 = left
*39 = right
*35 = end
*36 = home
*/

    var key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;

    if((key>=48)&&(key<=57)){
        if(/^\d{2}$/.test(ctrl.value)){
            ctrl.value += "-";
        }

        if(/^\d{2}-\d{8}$/.test(ctrl.value)){
            ctrl.value += "-";
        }
        return true;
    }
    else{
        if((key==8)||(key==46)||(key==35)||(key==36)||(key==37)||(key==39))
            return true;
        else
            return false;
    }
}

function ImprimirBrowser(){
    window.print();
}


function Imprimir(){
    var args        =   Imprimir.arguments;
    var page        =   "index.php?page=" + args[0];
    var queryString =   "&print=true";


    for(var i = 1; i < args.length; i+=2){
        var obj =   MM_findObj(args[i + 1]);

        if(obj){
            var objValue    =   obj.value;

            if(objValue == ""){
                objValue    =   "null";
            }

            queryString +=  "&" + args[i] + "=" + objValue;
        }
    }

    page                +=  queryString;
    window.open(page, "printpage", "location:no,status=no,toolbar=no,menubar=no");

}



function ShowAnticipoViatico(idExpediente){
    var page = "index.php?page=Viaticos.AnticipoDetalle&idExpediente=" + idExpediente;

    /*window.open(page, null, "height=600,width=800,status=no,toolbar=yes,scrollbars=yes,menubar=yes,location=no");*/
    var wnd =  window.open(page + "&dialog=true", "Reportes", "scrollbars=1,top=0,left=0,width=800,height=600,resizable=1,status=no,toolbar=no,menubar=no,location=no");
    wnd.focus();

}

function ShowObservacionesExpediente(idExpediente){
    var page = "index.php?page=Compras.ObservacionesExpediente&id=" + idExpediente;

    /*window.open(page, null, "height=300,width=600,status=no,toolbar=yes,scrollbars=yes,menubar=yes,location=no");*/
    var wnd =  window.open(page + "&dialog=true", "Reportes", "scrollbars=1,top=0,left=0,width=800,height=600,resizable=1,status=no,toolbar=no,menubar=no,location=no");
    wnd.focus();

}

function Highlight() {
                //debugger;
    var form    =   document.getElementsByTagName("form").item(0);
	var i 		= 	0;
	var found	=	false;

	while(i < form.elements.length && !found){
		var element	=	form.elements[i];

		switch(element.tagName.toLowerCase()){
			case "input":
				if(element.type == "text" && element.style.display != "none" && element.className.indexOf("DatePicker") == -1){
					found					=	true;
					element.className       =    "FieldInputHighlight";
					element.focus();
				}
			break;

			case "textarea":
			case "select":
				found	=	true;
			break;
		}

		i++;
	}

    var elements = document.getElementsByTagName("input");

    for(i = 0; i < elements.length; i++) {
        if (elements[i].type != "button" && elements[i].type != "submit" && elements[i].type != "reset" && elements[i].type != "hidden") {
            elements[i].onfocus=function(){
                this.select();
//                var classNameLocal  =  this.className;
//                alert(this.className)
//                classNameLocal = classNameLocal.substring(0, classNameLocal.indexOf("Highlight")) + "Highlight";
                if(this.className.indexOf("Highlight") == -1){
                    this.className       +=    "Highlight";
                }
//                alert(this.className)
				if(this.style.textAlign == "right"){
					this.style.paddingRight = "2px";
				}
            };
            elements[i].onblur=function() {
//               this.style.borderStyle = "none";
                var classNameLocal  =  this.className;
                classNameLocal = classNameLocal.substring(0, classNameLocal.indexOf("Highlight"));
               this.className = classNameLocal
            };
        }
    }

	var textAreas	=	document.getElementsByTagName("textarea");

	for(i = 0; i < textAreas.length; i++) {
            textAreas[i].onfocus=function(){
                this.select();
                this.className       +=    "Highlight";
                //this.style.border = "2px solid #6F9778";
            };
            textAreas[i].onblur=function() {
//                this.style.borderStyle = "none";
                var classNameLocal  =  this.className;
                classNameLocal = classNameLocal.substring(0, classNameLocal.indexOf("Highlight"));
               this.className = classNameLocal

            };

	}


}

function ShowOrdenPagoViaticos(id){
    var page = "index.php?page=Viaticos.OrdenPagoDetalle&id=" + id;

    /*window.open(page, null, "height=600,width=600,status=no,toolbar=yes,scrollbars=yes,menubar=yes,location=no");*/
    var wnd =  window.open(page + "&dialog=true", "Reportes", "scrollbars=1,top=0,left=0,width=800,height=600,resizable=1,status=no,toolbar=no,menubar=no,location=no");
    wnd.focus();

}

/**
 *
 * @access public
 * @return void
 **/
function ShowExpedienteDetalle(id){
    //debugger;
/*    var tBody   =   link.parentElement.parentElement;
    var trHead  =   tBody.rows[0];
    var tr      =   link.parentElement;
    var dataXml =   "<ExpedienteData>";

    for(var i = 0; i < trHead.cells.length; i++){
        dataXml +=  "<Field><Name>" + trHead.cells[i].innerHTML + "</Name><Value Align=\"" + tr.cells[i].align + "\">" + ((i > 0) ? tr.cells[i].innerHTML : tr.cells[i].firstChild.innerHTML) + "</Value></Field>";
    }

    dataXml     +=  "</ExpedienteData>";
    var page = "index.php?page=Reportes.DetalleExpediente&Data=" + escape(dataXml);

    var wnd = window.open(page, "DetalleExpediente", "height=600,width=600,status=no,toolbar=no,scrollbars=yes,menubar=no,location=no");
    wnd.focus();*/

    var page = "index.php?page=Reportes.DetalleExpediente&id=" + id;
    var wnd =  window.open(page + "&dialog=true", "DetalleExpediente", "scrollbars=1,top=0,left=0,width=800,height=600,resizable=1,status=no,toolbar=no,menubar=no,location=no");
    wnd.focus();
}

function ShowCuadroComparativo(id){

    var page = "index.php?page=Compras.CuadroComparativoDetalle&id=" + id;

    var wnd =  window.open(page + "&dialog=true", "Reportes", "scrollbars=1,top=0,left=0,width=800,height=600,resizable=1,status=no,toolbar=no,menubar=no,location=no");
    //var wnd =  window.open(page + "&dialog=true", "CuadroComparativo", "scrollbars=1,top=0,left=0,width=800,height=600,resizable=1,status=no,toolbar=no,menubar=no,location=no");
    wnd.focus();

}

function ShowRendiciones(id){
    var page = "index.php?page=Liquidaciones.Rendiciones&id=" + id;
    var wnd =  window.open(page + "&dialog=true", "Reportes", "scrollbars=1,top=0,left=0,width=800,height=600,resizable=1,status=no,toolbar=no,menubar=no,location=no");
    wnd.focus();
}

function ImprimirPDF(pdfName){
    var page            =   "libraries/includes/toPDF/toPDF.php?pdfName=" + pdfName;


    var auxiliar        =   MM_findObj("btnImprimir");
    //document.getElementById(auxiliar.id).style["display"] = "none";
    var padre           =   auxiliar.parentNode;
	padre.removeChild(auxiliar);


//    var content         =   window.document.forms[0].innerHTML;
    var content = window.document.body.innerHTML;
    //alert(content.indexOf("checked"));
    //var content         =   window.document.outerHTML;
    var textArea        =   MM_findObj("txtPDF");
    var formObj         =   window.document.forms[0];
    var formAction      =   formObj.action;
    textArea.value      =   content;
    formObj.action      =   page;
    //formObj.target      =   "ifmPDF";
    formObj.submit();
    //formObj.action      =   formAction;
}

function ViewImage(file){
	 var options = "fullscreen=" + 0 +
                 ",toolbar=" + 0 +
                 ",location=" + 0 +
                 ",status=" + 0 +
                 ",menubar=" + 0 +
                 ",scrollbars=" + 1 +
                 ",resizable=" + 0 +
                 ",width=" + 500 +
                 ",height=" + 800 +
                 ",left=" + 0 +
                 ",top=" + 0;

	var wnd = window.open(file,"Imagen",options);
    //var wnd =  window.open(file + "&dialog=true", "Reportes", "scrollbars=1,top=0,left=0,width=450,height=450,resizable=1,status=no,toolbar=no,menubar=no,location=no");
    wnd.focus();
}

// Funciones creadas para SGRH

function DefaultButton(pevent, ctrl, buttonName){
    var levent = window.event ? window.event : pevent;
    var tecla = levent.keyCode;
    var button;

    if(tecla==13){
        button = MM_findObj('ctl0$Main$'+buttonName);
        button.click();
    }

    return false;
}

function Dialog(URL,x1,y1){
    var args = Dialog.arguments;
    var windowName = "Ventana";

    if(args.length > 3){
        windowName  += args[3];
    }

    var x=screen.width;
    var y=screen.height;
    var params="'position: absolute, top=" + (y-y1)/2 + ", left=" + (x-x1)/2 + ", height=" + y1 + ", width=" + x1 + "'";
    window.open(URL, windowName, params);
}

function ScrollDialog(URL,x1,y1){
    var args = ScrollDialog.arguments;
    var windowName = "Ventana";

    if(args.length > 3){
        windowName  += args[3];
    }

    var x=screen.width;
    var y=screen.height;
    var params="'position: absolute, top=" + (y-y1)/2 + ", left=" + (x-x1)/2 + ", height=" + y1 + ", width=" + x1 + ", scrollbars=yes, menubar=no'";
    window.open(URL, windowName, params);
}

function Reload(btnClientID){
    var btn = MM_findObj(btnClientID, window.opener.document);
    btn.click();
    window.close();
}

function NextTab(pevent, nextcontrol, nexttab){
    var levent = window.event ? window.event : pevent;
    var tecla = levent.keyCode;
    var control;

    if(tecla==9){
        control = MM_findObj('ctl0$Main$'+nextcontrol);

        if(control==null){
            control = MM_findObj('ctl0_Main_'+nextcontrol);
        }

        tab = MM_findObj('ctl0_Main_'+nexttab+'_0');
        tab.click();
        control.focus();
        return false;
    }
    else{
        return true;
    }
}

function TabResultados(){
    tab = MM_findObj('ctl0_Main_tvwResultados_0');
    tab.click();
    return true;
}

//agregado por Jorge el 15/09/2009

	// Esta Funcion se utiliza en la pagina "Tecnica.ConceptoContrato" para el calculo automatico de medicion.
	function CalcularSuma(actual)
	{
		var Total=0;
		var nodeNext = Siguiente(actual);
		var nodePrevious = Anterior(actual);
		Total= parseFloat(actual.value) + parseFloat(nodePrevious.innerText);
		if(isNaN(Total))
			nodeNext.value=0;
		else
			nodeNext.value=Total;

	}

	function Anterior(actual)
    {
		var anterior= getPreviousCtrl(actual.parentNode.parentNode,actual.id);
 		return(anterior);
    }

    function getPreviousCtrl(oTr, oId)
    {
	 var td = oTr.firstChild;
	 var node = null;
	 while ( (td) && (!node) )
	 {
		if (td.firstChild.id == oId)
		{
			node = td.previousSibling.firstChild;
		}
		td = td.nextSibling;
	 }
	  return(node);
    }

	function Siguiente(actual)
    {
		var siguiente= getNextCtrl(actual.parentNode.parentNode,actual.id);
 		return(siguiente);
    }

    function getNextCtrl(oTr, oId)
    {
	 var td = oTr.firstChild;
	 var node = null;
	 while ( (td) && (!node) )
	 {
		if (td.firstChild.id == oId)
		{
			node = td.nextSibling.firstChild;
		}
		td = td.nextSibling;
	 }
	  return(node);
    }


function AbrirPopup(url){
	var x=screen.width;
    var y=screen.height;
	var params="'position: absolute, top=" + (y-650)/2 + ", left=" + (x-550)/2 + ", height=" + 550 + ", width=" + 650 + ", scrollbars=yes, menubar=no'";
    window.open(url, "Ventana", params);
}
function ventanaModal(url,crtl){

	var id=document.getElementById("ctl0_Main_"+crtl).value;
	var x=screen.width;
    var y=screen.height;
	var params="'position: absolute, top=" + (y-650)/2 + ", left=" + (x-550)/2 + ", height=" + 550 + ", width=" + 650 + ", scrollbars=yes, menubar=no'";
	if(id!='')
			url = url + "&id=" + id;
	else
			url = url ;
	ventana = window.open(url,"Ventana", params);
	ventana.focus();
}